package com.qdsg.ysg.doctor.ui.adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.util.UtilString;
import com.rest.response.PrescriptionListResponse;

import java.util.List;


/**
 * Created by HP on 2020/3/2.
 */

public class AddMedicineListAdapter extends RecyclerView.Adapter<AddMedicineListAdapter.Holder> {

    AppCompatActivity context;
    List<PrescriptionListResponse.Prescription> list;

    public AddMedicineListAdapter(AppCompatActivity context, List<PrescriptionListResponse.Prescription> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public AddMedicineListAdapter.Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        AddMedicineListAdapter.Holder myHolder;
        myHolder = new AddMedicineListAdapter.Holder(LayoutInflater.from(context).inflate(R.layout.item_add_medicine, parent, false));
        return myHolder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(AddMedicineListAdapter.Holder holder, final int position) {
        holder.tv_medicine_name.setText(list.get(position).name);
//        holder.tv_medicine_base_num.setText(list.get(position).drugFrequency + "  " + list.get(position).drugDose + list.get(position).specialUnit + "/次" + "   " + list.get(position).drugChannel);
        holder.tv_medicine_base_num.setText(list.get(position).drugFrequency + "  " + list.get(position).drugDose  + "   " + list.get(position).drugChannel);
        holder.tv_medicine_num.setText(UtilString.str2Int(list.get(position).drugNumber));
        holder.tv_medicine_price.setText(list.get(position).expense);
        holder.btn_del.setOnClickListener(v -> {
            list.remove(position);
            notifyDataSetChanged();
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class Holder extends RecyclerView.ViewHolder {

        TextView tv_medicine_name, tv_medicine_num, tv_medicine_base_num, tv_medicine_price;
        ImageView btn_del;

        public Holder(View itemView) {
            super(itemView);
            tv_medicine_name = itemView.findViewById(R.id.tv_medicine_name);
            tv_medicine_num = itemView.findViewById(R.id.tv_medicine_num);
            tv_medicine_base_num = itemView.findViewById(R.id.tv_medicine_base_num);//计量
            tv_medicine_price = itemView.findViewById(R.id.tv_medicine_price);
            btn_del = itemView.findViewById(R.id.btn_del);
        }
    }
}
